<template>
  <div style="width:100%">
    <el-form ref="dataForm" inline label-width="120px">
      <el-form-item prop="name">
        <el-input v-model="name" placeholder="姓名"></el-input>
      </el-form-item>
    </el-form>
    <el-table stripe :data="tableList" border style="width: 100%;height:100%" size="mini">
      <el-table-column
        prop="name"
        sortable
        header-align="center"
        align="center"
        width="80px"
        label="姓名"
      ></el-table-column>
      <el-table-column prop="departName" sortable header-align="center" align="center" label="部门"></el-table-column>
      <el-table-column
        prop="roleName"
        sortable
        header-align="center"
        align="center"
        width="80px"
        label="角色"
      ></el-table-column>
      <el-table-column
        v-if="isCar"
        prop="licenseNum"
        sortable
        header-align="center"
        align="center"
        label="车牌"
      ></el-table-column>
      <el-table-column prop="enterTime" sortable header-align="center" align="center" label="进入时间"></el-table-column>

      <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
        <template slot-scope="scope">
          <el-button
            type="danger"
            v-if="isAuth('sys:them:del')"
            size="small"
            @click="deleteHandle(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dataList: [],
      name: "",
      dataTitle: "",
      isCar: false
    };
  },
  computed: {
    tableList() {
      let list = [];
      if (!this.name) {
        list = this.dataList;
      } else {
        list = this.dataList.filter(item => {
          return item.name.indexOf(this.name) !== -1;
        });
      }
      return list;
    }
  },
  created() {
    console.log(sessionStorage.userList, sessionStorage.themTitle);
    this.dataList = JSON.parse(sessionStorage.userList);
    this.dataTitle = sessionStorage.themTitle;
    if (
      this.dataTitle.indexOf("车") > -1 ||
      this.dataTitle.indexOf("生产区") > -1
    ) {
      this.isCar = true;
    }
  },
  methods: {
    // 删除
    deleteHandle(row) {
      var ids = row.id;
      var licenseNum = row.licenseNum;
      let realId = ids || licenseNum;
      let index = this.dataList.findIndex(
        item => item.id == ids || licenseNum == row.licenseNum
      );
      console.log(row, index);
      this.$confirm(
        `确定对 [ ${ids || licenseNum} ] 进行 [ "删除" ] 操作?`,
        "提示",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(() => {
          let data = {
            licenseNum: licenseNum,
            id: ids,
            is_del: "1"
          };

          this.$http({
            url: this.$http.adornUrl("/employee/deleteGroupRecord"),
            method: "post",
            params: this.$http.adornParams({
              page: this.pageIndex,
              data: JSON.stringify(data)
            })
          }).then(({ data }) => {
            if (data && data.code === 0) {
              this.dataList.splice(index, 1);
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {}
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        })
        .catch(() => {});
    }
  }
};
</script>

<style>
</style>